<?php
// +----------------------------------------------------------------------
// | RXThinkCMF_EVTP5.1_PRO前后端分离旗舰版框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2018~2021 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | 作者: ZhangXuanNeng <rxthinkcmf@163.com>
// +----------------------------------------------------------------------
// | 免责声明:
// | 本软件框架禁止任何单位和个人用于任何违法、侵害他人合法利益等恶意的行为，禁止用于任何违
// | 反我国法律法规的一切平台研发，任何单位和个人使用本软件框架用于产品研发而产生的任何意外
// | 、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带
// | 或衍生的损失等)，本团队不承担任何法律责任。本软件框架只能用于公司和个人内部的法律所允
// | 许的合法合规的软件产品研发，详细声明内容请阅读《框架免责声明》附件；
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\model\BoxGame;
use app\admin\service\BoxStatisticsGameOverviewService;
use app\admin\service\BoxStatisticsGameRemainService;
use app\admin\service\BoxStatisticsMemberltvService;
use app\admin\service\BoxStatisticsMemberpayltvService;
use app\admin\service\BoxStatisticsMemberpayRateService;
use app\admin\service\BoxStatisticsMpayRemainService;
use app\common\controller\Export;
use Exception;

class BoxStatisticsGame extends Backend
{

    /**
     * 获取游戏
     * @return void
     */
    public function getGameList()
    {
        $gameList = BoxGame::field(['id', 'game_name'])->order("id DESC")->select();
        if (!empty($gameList)) {
            foreach ($gameList as &$item) {
                $item['game_name'] = $item['id'] . '/' . $item['game_name'];
            }
        }
        $this->jsonReturn(message("操作成功", true, $gameList));
    }


    /**
     * @Notes:数据总览
     * @Interface overviewList
     */
    public function gameOverviewList()
    {
        $this->service = new BoxStatisticsGameOverviewService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出数据总览
     * @Interface overviewExport
     */
    public function gameOverviewExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }
        if (isset($param['box_game_id']) && !empty($param['box_game_id'])) {
            $map[] = ['box_game_id', '=', $param['box_game_id']];
        }

        $Export = new Export();
        $Export->gameOverviewExport($param, $map);
    }


    /**
     * @Notes:游戏总表
     * @Interface overviewList
     */
    public function gameTotalList()
    {
        $this->service = new BoxStatisticsGameOverviewService();
        $result        = $this->service->gameTotalList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出游戏总表
     * @Interface overviewExport
     */
    public function gameTotalExport()
    {
        $param  = request()->param();
        $Export = new Export();
        $Export->gameTotalExport($param);
    }


    /**
     * @Notes:用户留存
     * @Interface overviewList
     */
    public function gameRemainList()
    {
        $this->service = new BoxStatisticsGameRemainService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出用户留存
     * @Interface gameRemainExport
     */
    public function gameRemainExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }
        if (isset($param['box_game_id']) && !empty($param['box_game_id'])) {
            $map[] = ['box_game_id', '=', $param['box_game_id']];
        }

        $Export = new Export();
        $Export->gameRemainExport($param, $map);
    }


    /**
     * @Notes:付费用户留存
     * @Interface gameMpayRemainList
     */
    public function gameMpayRemainList()
    {
        $this->service = new BoxStatisticsMpayRemainService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出付费用户留存
     * @Interface gameMpayRemainExport
     */
    public function gameMpayRemainExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }
        if (isset($param['box_game_id']) && !empty($param['box_game_id'])) {
            $map[] = ['box_game_id', '=', $param['box_game_id']];
        }

        $Export = new Export();
        $Export->gameMpayRemainExport($param, $map);
    }


    /**
     * @Notes:持续付费率
     * @Interface gameMemberpayRateList
     */
    public function gameMemberpayRateList()
    {
        $this->service = new BoxStatisticsMemberpayRateService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出持续付费率
     * @Interface gameMemberpayRateExport
     */
    public function gameMemberpayRateExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }
        if (isset($param['box_game_id']) && !empty($param['box_game_id'])) {
            $map[] = ['box_game_id', '=', $param['box_game_id']];
        }

        $Export = new Export();
        $Export->gameMemberpayRateExport($param, $map);
    }

    /**
     * @Notes:用户LTV
     * @Interface gameMemberpayRateList
     */
    public function gameMemberltvList()
    {
        $this->service = new BoxStatisticsMemberltvService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出用户LTV
     * @Interface gameMemberltvExport
     */
    public function gameMemberltvExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }
        if (isset($param['box_game_id']) && !empty($param['box_game_id'])) {
            $map[] = ['box_game_id', '=', $param['box_game_id']];
        }

        $Export = new Export();
        $Export->gameMemberltvExport($param, $map);
    }


    /**
     * @Notes:付费用户LTV
     * @Interface gameMemberPayLtvList
     */
    public function gameMemberpayltvList()
    {
        $this->service = new BoxStatisticsMemberpayltvService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出付费用户LTV
     * @Interface gameMemberPayLtvExport
     */
    public function gameMemberpayltvExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }
        if (isset($param['box_game_id']) && !empty($param['box_game_id'])) {
            $map[] = ['box_game_id', '=', $param['box_game_id']];
        }

        $Export = new Export();
        $Export->gameMemberpayltvExport($param, $map);
    }

}
